package com.bdsoft.actions.departmentManage.Controller;

import com.bdsoft.actions.AcUrls;
import com.bdsoft.actions.departmentManage.DTO.DepartmentDTO;
import com.bdsoft.actions.departmentManage.Service.DepartmentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(AcUrls.DepartmentManage.departmentManageUrl)
@Tag(name = "部门相关接口")
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;

    @Operation(summary = "新增部门")
    @PostMapping(AcUrls.DepartmentManage.addDepartment)
    public ResponseEntity addDepartment(@RequestBody DepartmentDTO departmentDTO) {
        return ResponseEntity.ok(departmentService.addDepartment(departmentDTO));
    }

    @Operation(summary = "修改部门")
    @PostMapping(AcUrls.DepartmentManage.updateDepartment)
    public ResponseEntity updateDepartment(@RequestBody DepartmentDTO departmentDTO) {
        return ResponseEntity.ok(departmentService.updateDepartment(departmentDTO));
    }

    @Operation(summary = "删除部门")
    @PostMapping(AcUrls.DepartmentManage.deleteDepartment)
    public ResponseEntity deleteDepartment(@RequestParam String deptId) {
        return ResponseEntity.ok(departmentService.deleteDepartment(deptId));
    }

    @Operation(summary = "根据ID获取部门")
    @GetMapping(AcUrls.DepartmentManage.getDepartmentById)
    public ResponseEntity getDepartmentById(@RequestParam String deptId) {
        return ResponseEntity.ok(departmentService.getDepartmentById(deptId));
    }

    @Operation(summary = "获取所有部门")
    @GetMapping(AcUrls.DepartmentManage.getAllDepartments)
    public Map<String,Object> getAllDepartments() {
        return departmentService.getAllDepartments();
    }
    
    @Operation(summary = "查看部门下的用户")
    @GetMapping(AcUrls.DepartmentManage.getDepartMentUser)
    public Map<String,Object> getDepartMentUser() {
        return departmentService.getDepartMentUser();
    }

    @Operation(summary = "获取当前用户信息")
    @GetMapping("/current-user")
    public Map<String, Object> getCurrentUser(@RequestHeader(value = "X-User-Name", required = false) String username,
                                             @RequestHeader(value = "X-User-Id", required = false) String userId) {
        Map<String, Object> result = Map.of(
            "username", username != null ? username : "unknown",
            "userId", userId != null ? userId : "unknown",
            "message", "当前用户信息来自网关传递的Header"
        );
        return result;
    }
} 